<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>添加角色</title>
<link href="${ctx }/css/ztreeStyle.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="${ctx }/js/niceValidator/jquery.validator.css" />
<link href="${ctx }/css/ztree/zTreeStyle/zTreeStyle.css" rel="stylesheet" type="text/css" />
<link href="${ctx }/js/layui/css/layui.css" rel="stylesheet" type="text/css" />
<link href="${ctx }/css/ztree/demo.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="${ctx }/js/jquery/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="${ctx }/js/layer/layer.js"></script>
<script type="text/javascript" src="${ctx }/js/niceValidator/jquery.validator.js"></script>
<script type="text/javascript" src="${ctx }/js/niceValidator/local/zh_CN.js"></script>
<script type="text/javascript" src="${ctx }/js/common.js"></script>
<script type="text/javascript" src="${ctx }/js/ztree/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="${ctx }/js/ztree/jquery.ztree.excheck-3.5.js"></script>

</head>
<body>
<div class="listNavTitle">
  <p>
    <label>系统管理 ></label>
    <label>角色管理</label>
  </p>
</div>
<div class="formbody">
  <div class="formtitle"><span>新增角色</span></div>
<form id="submitForm">
  <ul class="forminfo">
    <li>
      <label>角色名称</label>
      <input name="roleName" type="text" class="dfinput"  data-rule="角色名称:required;"/>
    </li>
    <li>
      <label>角色模块</label>
      <select name="roleModuleType" onchange="roleTypeChange();" id="roleModuleType">
          <option value="sysman">系统管理</option>
          <option value="enterprise">企业角色</option>
          <option value="security">公安角色</option>
      </select>
    </li>
    <li>
      <label>角色授权</label>
      <div>
      	<input type="hidden" name="authResourceStr" id="authResourceStr" />
      	<ul id="dleft_tab1" class="ztree" style="width:335px;height:200px;"></ul>
      </div>
    </li>
	<li>
      <label>标识CODE</label>
      <input name="roleShrioCode" type="text" class="dfinput"  data-rule="标识CODE:required;"/>
    </li>
    <li>
      <label>角色描述</label>
      <textarea name="roleDes" style="width:500px;height:200px;border:1px solid black"></textarea>
    </li>
    <li>
      <label>&nbsp;</label>
      <button class="layui-btn layui-btn-normal" type="button" class="btn" id="submitBtn">确认保存</button>
    </li>
  </ul>
</form>
</div>
</body>
</html>
<script>
	$(document).ready(function(){
		$("#submitBtn").click(function(){
			selectQuan();
			baseAdd('${ctx}/sysman/systemRole/addSystemRole.do');
		});
		onloadMenu();
	});

    function roleTypeChange(){
        onloadMenu();
    }

	function onloadMenu(){
        var roleModuleType = $("#roleModuleType option:selected").val();
			var setting = {
			check: {
				enable: true
			},
			data: {
				simpleData: {
					enable: true
				}
			}
		};
			var jsondata="[";
			$.ajax({
					type:"POST",
					url:"${ctx }/sysman/authResource/authResourceAllList.do?moduleType="+roleModuleType,
					dataType:"json",
					async:false,
					success:function(data){
						for(var i=0;i<data.length;i++){
							jsondata+="{'pId':'"+data[i].authparentCode+"','id':'"+data[i].authCode+"','name':'"+data[i].authName+"'},"
						}
					}
				});
			jsondata = jsondata.substring(0,jsondata.length-1);
			jsondata+="]";
			jsondata=eval(jsondata);
			$.fn.zTree.init($("#dleft_tab1"), setting, jsondata);
			var zTree = $.fn.zTree.getZTreeObj("dleft_tab1");
			zTree.setting.check.chkboxType = { "Y" : "ps", "N" : "s" };
		}
		
	function selectQuan(){
		var treeObj = jQuery.fn.zTree.getZTreeObj("dleft_tab1");
	    var nodes = treeObj.getCheckedNodes(true);
		var nodeStr="";
		for(var i=0;i<nodes.length;i++){
			nodeStr+=nodes[i].id+",";
		}
		nodeStr = nodeStr.substring(0,nodeStr.length-1);
		$("#authResourceStr").val(nodeStr);
	}
</script>